<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Search result pagination - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/learning.lucene.pagination.html">Inglês (English)</a></li>
    <li><a href="../pt-br/learning.lucene.pagination.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.lucene.queries.html">Supported queries</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.paginator.html">Iniciando com o Zend_Paginator</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="learning.lucene.pagination" class="section"><div class="info"><h1 class="title">Search result pagination</h1></div>
    

    <p class="para">
        As <a href="learning.lucene.searching.html#learning.lucene.searching.identifiers" class="link">mentioned above</a>, search
        result hit objects use lazy loading for stored document fields. When any stored field is
        accessed, the complete document is loaded.
    </p>

    <p class="para">
        Do not retrieve all documents if you actually need to work only with some portion of them.
        Go through the search results and store document IDs (and optionally the score) somewhere to
        retrive documents from the index during the next script execution.
    </p>

    <div class="example" id="learning.lucene.pagination.example"><div class="info"><p><b>Example #1 Search result pagination example</b></p></div>
        

        <pre class="programlisting brush: php">
$cacheId = md5($query);

if (!$resultSet = $cache-&gt;load($cacheId)) {
    $hits = $index-&gt;find($query);
    $resultSet = array();
    foreach ($hits as $hit) {
        $resultSetEntry          = array();
        $resultSetEntry[&#039;id&#039;]    = $hit-&gt;id;
        $resultSetEntry[&#039;score&#039;] = $hit-&gt;score;

        $resultSet[] = $resultSetEntry;
    }

    $cache-&gt;save($resultSet, $cacheId);
}

$publishedResultSet = array();
for ($resultId = $startId; $resultId &lt; $endId; $resultId++) {
    $publishedResultSet[$resultId] = array(
        &#039;id&#039;    =&gt; $resultSet[$resultId][&#039;id&#039;],
        &#039;score&#039; =&gt; $resultSet[$resultId][&#039;score&#039;],
        &#039;doc&#039;   =&gt; $index-&gt;getDocument($resultSet[$resultId][&#039;id&#039;]),
    );
}
</pre>

    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="learning.lucene.queries.html">Supported queries</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="learning.paginator.html">Iniciando com o Zend_Paginator</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="learning.html">Conhecendo o Zend Framework</a></li>
  <li class="header up"><a href="learning.lucene.html">Iniciando com o Zend_Search_Lucene</a></li>
  <li><a href="learning.lucene.intro.html">Zend_Search_Lucene Introduction</a></li>
  <li><a href="learning.lucene.index-structure.html">Lucene Index Structure</a></li>
  <li><a href="learning.lucene.index-opening.html">Index Opening and Creation</a></li>
  <li><a href="learning.lucene.indexing.html">Indexing</a></li>
  <li><a href="learning.lucene.searching.html">Searching</a></li>
  <li><a href="learning.lucene.queries.html">Supported queries</a></li>
  <li class="active"><a href="learning.lucene.pagination.html">Search result pagination</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>